package com.crm.system.controller;

import com.crm.model.JsonMessage;
import com.crm.security.AuthUserDetail;
import com.crm.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("user")
public class SysController {
    @Autowired
    private SysUserService userService;
    @GetMapping("info")
    @ResponseBody
    public JsonMessage userinfo(Authentication auth)
    {
        AuthUserDetail detail= (AuthUserDetail) auth.getDetails();
        //AuthUserDetail user=JwtUtil.parseJWT(token);
       // SysUser user =userService.getByLoginName(auth.getName());
        JsonMessage message=new JsonMessage();
       // message.setData(user);
        Map<String,Object> data=new HashMap<>();
        data.put("name",detail.getUsername());
        data.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        message.setData(data);
        return message;
    }

    @PostMapping("logout")
    @ResponseBody
    public JsonMessage logout(@RequestHeader("X-Token") String token)
    {
        JsonMessage message=new JsonMessage();
        return message;
    }

}
